package com.crm.service.impl.orderManager;

import com.crm.dao.mapper.customMapper.orderManagerCustomMapper.CustomerOrderInvoiceCustomMapper;
import com.crm.dao.mapper.orderManager.CustomerOrderInvoiceMapper;
import com.crm.model.entity.orderManager.CustomerOrderActivityRelation;
import com.crm.model.entity.orderManager.CustomerOrderActivityRelationExample;
import com.crm.model.entity.orderManager.CustomerOrderInvoice;
import com.crm.model.entity.orderManager.CustomerOrderInvoiceExample;
import com.crm.model.qo.orderManager.OrderInvoiceQO;
import com.crm.model.vo.orderManager.ApplyOrderInvoiceInfoVO;
import com.crm.model.vo.orderManager.OrderInvoiceVO;
import com.crm.model.vo.sys.InvoiceCompanyVO;
import com.crm.service.orderManager.CustomerOrderInvoiceDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/4/26 11:42
 */
@Service
public class CustomerOrderInvoiceDbServiceImpl implements CustomerOrderInvoiceDbService {

    @Autowired
    private CustomerOrderInvoiceCustomMapper customerOrderInvoiceCustomMapper;

    @Autowired //自动生成
    private CustomerOrderInvoiceMapper customerOrderInvoiceMapper;

    /**
     * 新增发票申请
     * @param customerOrderInvoice
     */
    @Override
    public void addOrderInvoice(CustomerOrderInvoice customerOrderInvoice) {
        customerOrderInvoiceMapper.insertSelective(customerOrderInvoice);
    }

    /**
     * 查询开票记录
     * @param qo
     * @param order
     * @param dateUnit
     * @return
     */
    @Override
    public List<OrderInvoiceVO> selectOrderInvoiceList(OrderInvoiceQO qo, String order, Integer dateUnit) {
        return customerOrderInvoiceCustomMapper.selectOrderInvoiceList(qo,order,dateUnit);
    }

    /**
     * 修改开票审批状态
     * @param id
     * @param type
     */
    @Override
    public void updateExamineStatus(String id, String type) {
        customerOrderInvoiceCustomMapper.updateExamineStatus(id,type);
    }

    /**
     * 根据id查询发票信息
     * @param id
     * @return
     */
    @Override
    public CustomerOrderInvoice selectByPrimaryKey(String id) {
        return customerOrderInvoiceMapper.selectByPrimaryKey(id);
    }

    /**
     * 删除开票信息
     * @param id
     */
    @Override
    public void delOrderInvoice(String id) {
        customerOrderInvoiceCustomMapper.delOrderInvoice(id);
    }

    /**
     * 查看发票申请详情
     * @param chsCustomerOrderInvoiceId
     * @return
     */
    @Override
    public ApplyOrderInvoiceInfoVO selectApplyOrderInvoiceInfo(String chsCustomerOrderInvoiceId) {
        return customerOrderInvoiceCustomMapper.selectApplyOrderInvoiceInfo(chsCustomerOrderInvoiceId);
    }

    /**
     * 通过主键查询开票详情
     * @param chsCustomerOrderInvoiceId
     * @return
     */
    @Override
    public OrderInvoiceVO selectOrderInvoiceById(String chsCustomerOrderInvoiceId) {
        return customerOrderInvoiceCustomMapper.selectOrderInvoiceById(chsCustomerOrderInvoiceId);
    }

    /**
     * 修改申请开票信息
     * @param customerOrderInvoice
     */
    @Override
    public void updateOrderInvoice(CustomerOrderInvoice customerOrderInvoice) {
        customerOrderInvoiceMapper.updateByPrimaryKeySelective(customerOrderInvoice);
    }

    @Override
    public List<CustomerOrderInvoice> selectOrderInvoiceByOrderId(String orderId) {
        CustomerOrderInvoiceExample customerOrderInvoiceExample = new CustomerOrderInvoiceExample();
        CustomerOrderInvoiceExample.Criteria criteria = customerOrderInvoiceExample.createCriteria();
        criteria.andProductOrderIdEqualTo(orderId);
        criteria.andExamineStatusNotEqualTo(2);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderInvoice> orderInvoices = customerOrderInvoiceMapper.selectByExample(customerOrderInvoiceExample);
        return orderInvoices;
    }
}
